<!--
// +----------------------------------------------------------------------
// | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
// +----------------------------------------------------------------------
// | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.luckyhhy.cn
// +----------------------------------------------------------------------
// | Author: LuckyHhy <jackhhy520@qq.com>
// +----------------------------------------------------------------------
// | Date: 2020/3/3-15:34
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
*-->

{extend name='public/base' /}


{block name="css"}
<link href="__PLUGS__/layui/lay/hhymodel/openTable/openTable.css?v=1.0" rel="stylesheet">
<link href="__PLUGS__/dropdown/dropdown.css?v=1.0" rel="stylesheet">
{/block}
{block name="content"}

<div class="layui-col-md12">

    <div class="layui-card">
        <div class="layui-card-body layui-row ">

            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">

                    <div class="layui-inline">
                        <label class="layui-form-label">文章栏目：</label>
                        <div class="layui-input-inline">
                            {:widget('common/forms/singleSelect',array('category_id|2|所属分类|title_show|id',$tree,0))}
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">文章搜索：</label>
                        <div class="layui-input-inline">
                            <input name="title" class="layui-input" value="" type="text" placeholder="请输入标题">
                        </div>
                    </div>

                    <div class="layui-inline" style="padding-left: 20px;">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button class="layui-btn icon-btn layui-btn-normal layui-btn-sm" onclick="javascript:window.location.reload();">
                            <i class="layui-icon layui-icon-refresh"></i> 重置
                        </button>
                    </div>

                </div>

            </form>

        </div>

    </div>


    <div class="layui-card">
        <div class="layui-card-body">
            <!--表格区-->
            <div class="yys-fluid yys-wrapper">
                <div class="layui-row lay-col-space20">
                    <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg12">
                        <section class="yys-body">
                            <div class="yys-body-content clearfix changepwd">
                                <div class="layui-col-lg12 layui-col-md10 layui-col-sm12 layui-col-xs12" style="width:100%">
                                    <div class="user-tables">
                                        <table id="tableFilter" lay-filter="tableFilter"> </table>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>


        </div>
    </div>

</div>


{/block}


{block name="js"} <!--js处理区-->

<!--模板-->
<script type="text/html" id="operationTpl">
    <button class="layui-btn layui-btn-xs" lay-filter="ft{{d.id}}" lay-dropdown="{align:'center', menus: [{layIcon:'layui-icon-edit',txt: '编辑', event:'edit'}, {layIcon: 'layui-icon-delete',txt: '删除', event:'del'}]}">
        <span>操作</span>
        <i class="layui-icon layui-icon-triangle-d"></i>
    </button>
</script>

<script type="text/html" id="is_show">
    {{# if(d.is_show==1){ }}
    <span class="layui-badge layui-bg-green">显示</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-cyan">不显示</span>
    {{# } }}
</script>

<script type="text/html" id="is_top">
    {{# if(d.is_top==1){ }}
    <span class="layui-badge layui-bg-orange">置顶</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-gray">不置顶</span>
    {{# } }}
</script>

<script type="text/html" id="is_recommend">
    {{# if(d.is_recommend==1){ }}
    <span class="layui-badge layui-bg-blue">推荐</span>
    {{# }else{ }}
    <span class="layui-badge layui-bg-black">不推荐</span>
    {{# } }}
</script>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="add_article"><i class="layui-icon"></i>新增文章</button>
        <button class="layui-btn layui-btn-sm" lay-filter="ft" lay-dropdown="{align:'center', menus: [{layIcon:'layui-icon-chart',txt: '移动文章', event:'move'}, {layIcon: 'layui-icon-export',txt: '数据导出', event:'export'}
        , {layIcon: 'layui-icon-refresh',txt: '刷新表格', event:'reload'},{layIcon: 'layui-icon-delete',txt: '删除数据', event:'del'}]}">
            <span>更多操作</span>
            <i class="layui-icon layui-icon-triangle-d"></i>
        </button>
    </div>
</script>

<script>
    layui.config({
        base: "__PLUGS__/dropdown/"
    }).use(['element', 'table', 'form', 'jquery', 'lucky','openTable','dropdown'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky=layui.lucky;
        var openTable=layui.openTable;
        var dropdown = layui.dropdown;

        form.render();

        // layer.load(2);
        openTable.render({
            elem: '#tableFilter',
            url:"{:url('article/index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            even: true, //开启隔行背景
            defaultToolbar: ['filter', 'print'],
            id:'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','last'] //自定义分页布局
                //,curr: 5 //设定初始在第 5 页
                ,groups: 5 //只显示 1 个连续页码
                ,first: false //不显示首页
                ,last: false //不显示尾页
                ,limit:30
                ,limits:[20,30,50,60]
            },
           // height: 'full-100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {type: 'checkbox'},
                {field: 'title', minWidth: 130, title: '文章标题',templet:function (d) {
                        return '<font  onmouseover="tis(this)" color="red" data-title="'+d.title+'">'+d.title+'</font>'
                    }},
                {field: 'name',style:'cursor: pointer;',title: '文章栏目',width:150},
                {field: 'description', title: '文章描述', width: 180, style:'cursor: pointer;', templet:function (d) {
                        return '<font  onmouseover="tis(this)" data-title="'+d.description+'">'+d.description+'</font>'
                    }},
                {field: 'url', title: '地址', width: 150, style:'cursor: pointer;', templet:function (d) {
                        return '<a href="'+d.url+'" target="_blank" title="点击访问"><i class="layui layui-icon layui-icon-link "></i>: '+d.url+'</a>'
                    }},
                {field:'is_show',title:'是否显示',templet: '#is_show',align: 'center',width:90 ,unresize: true},
                {field: 'hits',style:'cursor: pointer;',title: '浏览数',width:90,sort:true},
                {field:'is_top',title:'是否置顶',templet: '#is_top',align: 'center',width:90 ,unresize: true},
                {field:'is_recommend',title:'是否推荐',templet: '#is_recommend',align: 'center',width:90 ,unresize: true},
                {field: 'create_time', title: '添加时间',align: 'center',width:160,sort:true},
                {fixed: 'right',templet: '#operationTpl', width: 130, align: 'center', title: '操作'}
            ]],
            //注：展开的列Items
             openCols: [
            //  1、普通文本
            {field: 'keywords', title: '关键词'},
            {field: 'author', title: '作者'},
            {field: 'source', title: '来源'},
            {field: 'comment_num', title: '评论数量'},
            {field: 'ip', title: 'ip地址'},
            //	4、可选择的类型 select
        ]
            //注：监听排序 {openTable}
         ,sort: function (obj) {
            console.log(obj)
        }
        //注：监听修改 {openTable}
       ,edit: function (obj) {
            // layui.table.reload('#test');
        }

        //注：0：同时只展开一项 1：一直展开不关闭之前  def：0 {openTable}
       , openType: 0
        ,done: function (res) {
                dropdown.suite();
                layer.closeAll('loading');
            }
        });


        /**
         * 表格搜索
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch("table_id",obj.field); //查询
            return false;
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            // console.log(JSON.stringify(data));
            var _id=parseInt(data.id);
            var layEvent = obj.event;
            if(layEvent==="edit"){
                var urls="{:url('editArticle')}?id="+_id;
                lucky.CreateForm("编辑文章信息",'55%','70%',urls,"table_id",0,1);

            }else if(layEvent==="del"){
                lucky.Delete_data(_id,"{:url('del')}","table_id");
            }
        });


        //头工具栏事件
        table.on('toolbar(tableFilter)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch(obj.event){
                case 'add_article':
                    lucky.CreateForm("添加文章",'55%','70%',"{:url('addArticle')}","table_id",0,1);
                    break;
                case 'del':
                    var num=0;
                    var id=[];
                    for (var i in data) {
                        num++;
                        id.push(data[i].id);
                    }
                    if (num<1) {
                        layer.msg("请选择一项",{time:1500});return false;
                    }
                    lucky.Delete_data(id,"{:url('del')}",obj.config.id);
                    break;
                case 'reload':
                    lucky.CreateReload(obj.config.id);
                    break;
                case 'export':
                    var n=0,iD=[];
                    for (var i in data) {
                        n++;
                        iD.push(data[i].id);
                    }
                    if (n<1){
                        layer.confirm('确定导出全部数据?', function(index){
                            layer.close(index);
                           window.location.href="{:url('export')}?id=all";
                        })
                    }else {
                        layer.confirm('确定导出选中的数据?', function(index){
                            layer.close(index);
                            window.location.href="{:url('export')}?id="+iD;
                        })
                    }
                    break;
                case 'move':
                    var nums=0;
                    var ids=[];
                    for (var i in data) {
                        nums++;
                        ids.push(data[i].id);
                    }
                    if (nums<1) {
                        layer.msg("请选择一项",{time:1500});return false;
                    }
                    $.post('{:url("category/moveSelect")}',{ids:ids},function(data){
                        layer.open({
                            type: 1,
                            title: '数据移动',
                            area: ['auto', '490px'],
                            content: data //这里content是一个普通的String
                        });
                        form.render('select');//刷新重新加载select

                        form.on('select(category_id)', function(data){
                            //  param.to_category_id = data.value;
                            var selected_text = $(data.elem).find("option:selected").text();
                            //确认移动
                            layer.confirm('确定批量移动至【'+selected_text+'】?', function(index){
                                $.post('{:url("article/removeCategory")}',{ids:ids,category_id:data.value},function(data){
                                    if(data.code == 1){
                                        layer.closeAll();
                                        layer.msg(data.msg, {icon: 1, time: 1000}, function(){
                                            lucky.CreateReload(obj.config.id);
                                        });
                                    }else{
                                        layer.msg(data.msg, {icon: 2,anim: 6, time: 1000});
                                    }
                                }).error(function () {
                                    layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                                });
                            });
                        });
                    }).error(function () {
                        layer.msg('服务器错误', {icon: 2, anim: 6, time: 1000});
                    });
                    break;
            }
        });

    });

</script >


{/block}
